<template>
  <div class="information">
    <div class="title">
      <div class="l">社区最新资讯</div>
      <div class="r" @click="viewMore">查看更多 >>></div>
    </div>
    <div class="box">
      <div
        class="item"
        v-for="(item, index) in data"
        :key="index"
        @click="itemCLickHandel(item)"
      >
        <div class="item_t"><img :src="QNURL + item.cover" alt="" /></div>
        <div class="item_b">
          <div class="name">{{ item.title }}</div>
          <div class="content">{{ item.digest }}</div>
          <div class="time">{{ item.updateTime }}</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { QNURL } from "@/config/urlConfig";
import { useRouter } from "vue-router";
import { useCommonStore } from "@/store/modules/common";

const commonStore = useCommonStore();

const router = useRouter();

defineProps({
  data: {
    type: Array as () => any,
    default: () => []
  }
});

function viewMore() {
  router.push({
    path: "/community"
  });
  commonStore.SET_CURRENT_NAV_INDEX(3);
}

function itemCLickHandel(item: any) {
  router.push({
    path: "/communityDetail",
    query: {
      articleId: item.id
    }
  });
}
</script>

<style lang="scss" scoped>
.information {
  width: 100%;
  margin-top: 50px;

  .title {
    width: 100%;
    height: 50px;
    // background: linear-gradient(to left, #fff, #e6e5e5);
    border-bottom: 2px solid #dedfe0;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    padding: 0 20px;

    .l,
    .r {
      flex: 1;
      font-size: 20px;
      font-weight: bold;
    }

    .r {
      text-align: right;
      font-size: 14px;
      color: #666;
      cursor: pointer;
    }
  }

  .box {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    .item {
      width: 590px;
      height: 450px;
      background-color: #fff;
      border-radius: 10px;
      // padding: 20px;
      box-shadow: 1px 1px 1px 1px #dedfe0;
      cursor: pointer;
      margin-right: 10px;
      display: flex;
      flex-direction: column;
      margin-bottom: 10px;
      overflow: hidden;

      &:last-of-type {
        margin-right: 0;
      }

      &_t {
        width: 100%;
        height: 70%;
      }

      &_b {
        height: 30%;
        width: 100%;
        padding: 10px;

        .name {
          font-size: 20px;
        }

        .content {
          display: -webkit-box;
          width: 100%;
          height: 60px;
          overflow: hidden;
          text-overflow: ellipsis;
          -webkit-line-clamp: 3; /* 控制显示的行数 */
          // white-space: nowrap;
          -webkit-box-orient: vertical;
          margin: 5px 0;
        }

        .time {
          color: var(--secondary-color);
        }
      }
    }
  }
}
</style>
